#include "comm/my_crc.h"
#include "comm/my_log.h"

int main() {
    MY_LOG_DEBUG("crc16: %d", my_crc16((const u_char *)"abcdef", strlen("abcdef")));
    MY_LOG_DEBUG("crc32 short: %d", my_crc32_short((const u_char *)"abcdef", strlen("abcdef")));
    MY_LOG_DEBUG("crc32 long: %d", my_crc32_long((const u_char *)"abcdef", strlen("abcdef")));


    const char *str = "aaaaabbbbbbbbccccccddddeeeeeffffffgggggghhhhhhhhhhiiiiiiiiiiijjjjjjjjjj"
                      "kkkkkkllllllmmmmmmmnnnnnnnnnooooooopppppqqqqqqqqrrrrrrrrsssssssttttttt"
                      "1111111122222222222233333333333344444444444455555555555555566666666666"
                      "7777777888888888899999999999999000000000000000000000000000000000000000";
    MY_LOG_DEBUG("crc32 short: %ld", my_crc32_short((const u_char *)str, strlen(str)));
    MY_LOG_DEBUG("crc32 long: %ld", my_crc32_long((const u_char *)str, strlen(str)));

    uint32_t crc_sum = 0;
    my_crc32_init(crc_sum);
    const char *str1 = "aaaaabbbbbbbbccccccddddeeeeeffffffgggggghhhhhhhhhhiiiiiiiiiiijjjjjjjjjj";
    my_crc32_update(&crc_sum, (const u_char *)str1, strlen(str1));
    const char *str2 = "kkkkkkllllllmmmmmmmnnnnnnnnnooooooopppppqqqqqqqqrrrrrrrrsssssssttttttt";
    my_crc32_update(&crc_sum, (const u_char *)str2, strlen(str2));
    const char *str3 = "1111111122222222222233333333333344444444444455555555555555566666666666";
    my_crc32_update(&crc_sum, (const u_char *)str3, strlen(str3));
    const char *str4 = "7777777888888888899999999999999000000000000000000000000000000000000000";
    my_crc32_update(&crc_sum, (const u_char *)str4, strlen(str4));
    my_crc32_final(crc_sum);

    if (crc_sum != my_crc32_short((const u_char *)str, strlen(str))) {
        MY_LOG_FATAL("except %ld, but got %ld", my_crc32_short((const u_char *)str, strlen(str)), crc_sum);
    }

    MY_LOG_DEBUG("test pass");
    return 0;
}